package logic

import (
	"context"
	"src/srcclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodsUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodsUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodsUpdateLogic {
	return &GoodsUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GoodsUpdateLogic) GoodsUpdate(req *types.GoodsUpdateRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	UpdateGoods, err := l.svcCtx.SrcRpc.UpdateGoods(l.ctx, &srcclient.UpdateGoodsRequest{
		GoodStatus: int64(req.GoodStatus),
		Id:         int64(req.Id),
	})
	if err != nil {
		return &types.Response{
			Code: "500",
			Msg:  err.Error(),
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: "200",
		Msg:  "状态修改成功",
		Data: UpdateGoods,
	}, nil

}
